<?php

  require("includes/FeedWriter.php");
  require("includes/connect.inc.php");
  require("includes/readLog.php");

  //Creating an instance of Writer class. 
  //The constant RSS2 is passed to mention the version
  $Feed = new FeedWriter(RSS2);
  
  $channelId=mysql_real_escape_string($_GET["channel_id"]);
  if($channelId==null||$channelId=="") die("channel not found.");
  
  $sql="select * from channel where id='$channelId' and rank='1'";
  $result = $db->sql_query($sql);
  
  if($db->sql_numrows($result)!=1) die("channel not found.");
  $row=$db->sql_fetchrow($result);
  
  //Setting the channel elements
  //Use wrapper functions for common channel elements  
  $Feed->setTitle($row[1]);
  $Feed->setLink($row[2]);
  $Feed->setDescription($row[3]);
  
  //Use core setChannelElement() function for other optional channels
  $Feed->setChannelElement('language', $row[5]);
  $Feed->setChannelElement('pubDate', date(DATE_RSS, $row[4]));
  
  /////////////////////
  $limit=20;
  $sql=" SELECT * 
	FROM `item`
	WHERE channelid = '$channelId' and isPublish=1
	ORDER BY pubdate asc
	LIMIT $limit";
  $result = $db->sql_query($sql);
  
  while($row=$db->sql_fetchrow($result)){
	  //Create an empty Item
	  $newItem = $Feed->createNewItem();
	  //Add elements to the  item
	  //Use wrapper functions to add common  elements
	  $newItem->setTitle($row[2]);
	  $newItem->setLink($row[3]);
	  //The parameter is a timestamp for setDate() function
	  $newItem->setDate($row[5]);
	  $newItem->setDescription($row[4]);
	  //Use core addElement() function for other supported optional elements
	  $newItem->addElement('author', $row[7]);
	  //Attributes have to passed as array in 3rd parameter
	  $newItem->addElement('guid', $row[6]);
	  $Feed->addItem($newItem);
  }
 
  //OK. Everything is done. Now genarate the .
  $Feed->genarateFeed();
  
  addReadLog($channelId,null);
  
  
?>
